﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSpotTableVMs
{
    public partial class EquipmentSpotTableListVM : BasePagedListVM<EquipmentSpotTable_View, EquipmentSpotTableSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentSpotTable_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSpotTable_View>>{

                 this.MakeGridHeader(x => x.EquipmentSpotTable_SpotStatus).SetTitle(@Localizer["Page.点检状态"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_LineId).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_LineCode).SetTitle(@Localizer["Page.产线编号"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_OpId).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_OpCode).SetTitle(@Localizer["Page.工位编号"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_UseOperator).SetTitle(@Localizer["Page.操作员"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTable_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentSpotTable_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSpotTable>()
                
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                 .CheckEqual(Searcher.Status, x => x.Status)
                  
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.UseOperator, x=>x.UseOperator)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentSpotTable_View
                {
				    ID = x.ID,
                    
                    EquipmentSpotTable_Equipment = x.Equipment.EquipName,
                    EquipmentSpotTable_SpotStatus=x.Status,
                    EquipmentSpotTable_LineId = x.LineId,
                    EquipmentSpotTable_LineCode = x.LineCode,
                    EquipmentSpotTable_OpId = x.OpId,
                    EquipmentSpotTable_OpCode = x.OpCode,
                    EquipmentSpotTable_UseOperator = x.UseOperator,
                    EquipmentSpotTable_CreateTime = x.CreateTime,
                    EquipmentSpotTable_UpdateTime = x.UpdateTime,
                    EquipmentSpotTable_CreateBy = x.CreateBy,
                    EquipmentSpotTable_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentSpotTable_View: EquipmentSpotTable
    {
        public SpotStatusEnum EquipmentSpotTable_SpotStatus { get; set; }
        public string EquipmentSpotTable_Equipment { get; set; }
        public long? EquipmentSpotTable_LineId { get; set; }
        public string EquipmentSpotTable_LineCode { get; set; }
        public long? EquipmentSpotTable_OpId { get; set; }
        public string EquipmentSpotTable_OpCode { get; set; }
        public string EquipmentSpotTable_UseOperator { get; set; }
        public DateTime? EquipmentSpotTable_CreateTime { get; set; }
        public DateTime? EquipmentSpotTable_UpdateTime { get; set; }
        public string EquipmentSpotTable_CreateBy { get; set; }
        public string EquipmentSpotTable_UpdateBy { get; set; }

    }

}